home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1468
/
calc.frm
< prev
next >
Wrap
Text File
|
1996-07-19
|
11KB
|
363 lines
VERSION 4.00
Begin VB.Form Calculator
BorderStyle = 1 'Fixed Single
Caption = "Calculator"
ClientHeight = 2520
ClientLeft = 6555
ClientTop = 345
ClientWidth = 2655
ClipControls = 0 'False
BeginProperty Font
name = "System"
charset = 0
weight = 700
size = 9.75
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 2925
Icon = "calc.frx":0000
Left = 6495
LinkMode = 1 'Source
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 2520
ScaleWidth = 2655
Top = 0
Width = 2775
Begin VB.PictureBox picReadout
Height = 375
Left = 120
ScaleHeight = 315
ScaleWidth = 2400
TabIndex = 19
Top = 105
Width = 2460
End
Begin VB.CommandButton Number
Caption = "7"
Height = 420
Index = 7
Left = 120
TabIndex = 7
Top = 600
Width = 420
End
Begin VB.CommandButton Number
Caption = "8"
Height = 420
Index = 8
Left = 600
TabIndex = 8
Top = 600
Width = 420
End
Begin VB.CommandButton Number
Caption = "9"
Height = 420
Index = 9
Left = 1080
TabIndex = 9
Top = 600
Width = 420
End
Begin VB.CommandButton Cancel
Caption = "C"
Height = 420
Left = 1680
TabIndex = 10
Top = 600
Width = 420
End
Begin VB.CommandButton CancelEntry
Caption = "CE"
Height = 420
Left = 2160
TabIndex = 11
Top = 600
Width = 420
End
Begin VB.CommandButton Number
Caption = "4"
Height = 420
Index = 4
Left = 120
TabIndex = 4
Top = 1080
Width = 420
End
Begin VB.CommandButton Number
Caption = "5"
Height = 420
Index = 5
Left = 600
TabIndex = 5
Top = 1080
Width = 420
End
Begin VB.CommandButton Number
Caption = "6"
Height = 420
Index = 6
Left = 1080
TabIndex = 6
Top = 1080
Width = 420
End
Begin VB.CommandButton Operator
Caption = "+"
Height = 420
Index = 1
Left = 1680
TabIndex = 12
Top = 1080
Width = 420
End
Begin VB.CommandButton Operator
Caption = "-"
Height = 420
Index = 3
Left = 2160
TabIndex = 13
Top = 1080
Width = 420
End
Begin VB.CommandButton Number
Caption = "1"
Height = 420
Index = 1
Left = 120
TabIndex = 1
Top = 1560
Width = 420
End
Begin VB.CommandButton Number
Caption = "2"
Height = 420
Index = 2
Left = 600
TabIndex = 2
Top = 1560
Width = 420
End
Begin VB.CommandButton Number
Caption = "3"
Height = 420
Index = 3
Left = 1080
TabIndex = 3
Top = 1560
Width = 420
End
Begin VB.CommandButton Operator
Caption = "X"
Height = 420
Index = 2
Left = 1680
TabIndex = 14
Top = 1560
Width = 420
End
Begin VB.CommandButton Operator
Caption = "/"
Height = 420
Index = 0
Left = 2160
TabIndex = 15
Top = 1560
Width = 420
End
Begin VB.CommandButton Number
Caption = "0"
Height = 420
Index = 0
Left = 120
TabIndex = 0
Top = 2040
Width = 900
End
Begin VB.CommandButton Decimal
Caption = "."
Height = 420
Left = 1080
TabIndex = 18
Top = 2040
Width = 420
End
Begin VB.CommandButton Operator
Caption = "="
Height = 420
Index = 4
Left = 1680
TabIndex = 16
Top = 2040
Width = 420
End
Begin VB.CommandButton Percent
Caption = "%"
Height = 420
Left = 2160
TabIndex = 17
Top = 2040
Width = 420
End
End
Attribute VB_Name = "Calculator"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
' Sample program that comes with VB.
' Adapted for VBMaxLCD.dll by Mike Stanley
' ------------------------------------------------------------------------
' Copyright (C) 1994 Microsoft Corporation
'
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Microsoft has no warranty,
' obligations or liability for any Sample Application Files.
' ------------------------------------------------------------------------
Option Explicit
Dim Readout As New CLCD
Dim Op1, Op2 ' Previously input operand.
Dim DecimalFlag As Integer ' Decimal point present yet?
Dim NumOps As Integer ' Number of operands.
Dim LastInput ' Indicate type of last keypress event.
Dim OpFlag ' Indicate pending operation.
Dim TempReadout
' Click event procedure for C (cancel) key.
' Reset the display and initializes variables.
Private Sub Cancel_Click()
Readout.Caption = Format(0, "0.")
Op1 = 0
Op2 = 0
Form_Load
End Sub
' Click event procedure for CE (cancel entry) key.
Private Sub CancelEntry_Click()
Readout.Caption = Format(0, "0.")
DecimalFlag = False
LastInput = "CE"
End Sub
' Click event procedure for decimal point (.) key.
' If last keypress was an operator, initialize
' readout to "0." Otherwise, append a decimal
' point to the display.
Private Sub Decimal_Click()
If LastInput = "NEG" Then
Readout.Caption = Format(0, "-0.")
ElseIf LastInput <> "NUMS" Then
Readout.Caption = Format(0, "0.")
End If
DecimalFlag = True
LastInput = "NUMS"
End Sub
' Initialization routine for the form.
' Set all variables to initial values.
Private Sub Form_Load()
DecimalFlag = False
NumOps = 0
LastInput = "NONE"
OpFlag = " "
With Readout
.BackColor = &H808080
.ForeColor = &H0&
Set .Container = picReadout
.Caption = Format(0, "0.")
End With
Decimal.Caption = Format(0, ".")
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Readout = Nothing
Set Calculator = Nothing
End Sub
' Click event procedure for number keys (0-9).
' Append new number to the number in the display.
Private Sub Number_Click(Index As Integer)
If LastInput <> "NUMS" Then
Readout.Caption = Format(0, ".")
DecimalFlag = False
End If
If DecimalFlag Then
Readout.Caption = Readout.Caption + Number(Index).Caption
Else
Readout.Caption = Left(Readout.Caption, InStr(Readout.Caption, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
End If
If LastInput = "NEG" Then Readout.Caption = "-" & Readout.Caption
LastInput = "NUMS"
End Sub
' Click event procedure for operator keys (+, -, x, /, =).
' If the immediately preceeding keypress was part of a
' number, increments NumOps. If one operand is present,
' set Op1. If two are present, set Op1 equal to the
' result of the operation on Op1 and the current
' input string, and display the result.
Private Sub Operator_Click(Index As Integer)
TempReadout = Readout.Caption
If LastInput = "NUMS" Then
NumOps = NumOps + 1
End If
Select Case NumOps
Case 0
If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
Readout.Caption = "-" & Readout.Caption
LastInput = "NEG"
End If
Case 1
Op1 = Readout.Caption
If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
Readout.Caption = "-"
LastInput = "NEG"
End If
Case 2
Op2 = TempReadout
Select Case OpFlag
Case "+"
Op1 = CDbl(Op1) + CDbl(Op2)
Case "-"
Op1 = CDbl(Op1) - CDbl(Op2)
Case "X"
Op1 = CDbl(Op1) * CDbl(Op2)
Case "/"
If Op2 = 0 Then
MsgBox "Can't divide by zero", 48, "Calculator"
Else
Op1 = CDbl(Op1) / CDbl(Op2)
End If
Case "="
Op1 = CDbl(Op2)
Case "%"
Op1 = CDbl(Op1) * CDbl(Op2)
End Select
Readout.Caption = Op1
NumOps = 1
End Select
If LastInput <> "NEG" Then
LastInput = "OPS"
OpFlag = Operator(Index).Caption
End If
End Sub
' Click event procedure for percent key (%).
' Compute and display a percentage of the first operand.
Private Sub Percent_Click()
Readout.Caption = Readout.Caption / 100
LastInput = "Ops"
OpFlag = "%"
NumOps = NumOps + 1
DecimalFlag = True
End Sub